﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using PMS.SANY.Util;

namespace PMS.SANY.Entity
{
    /// <summary>
    /// 计划状态
    /// </summary>
    public enum PlanStatus
    {
        /// <summary>
        /// 接收(待下发)
        /// </summary>
        Accept = 0,
        /// <summary>
        /// 执行中(已下发)
        /// </summary>
        Execute = 1,
        /// <summary>
        /// 已完成
        /// </summary>
        Complete = 2,
        /// <summary>
        /// 已取消
        /// </summary>
        Cancel = 3,
        /// <summary>
        /// 挂起
        /// </summary>
        Pending = 4,
    }

    /// <summary>
    /// 计划(生产订单)
    /// </summary>
    public partial class Plan : BusEntity
    {
        public Plan()
        {
            CreateTime = DateTime.Now;
        }

        /// <summary>
        /// 
        /// </summary>
        public string MonTaskId { set; get; }

        /// <summary>
        /// 计划状态(中控)
        /// </summary>
        public PlanStatus Status { set; get; }

        /// <summary>
        /// 订单号
        /// </summary>
        public string WipOrderNo { get; set; }

        /// <summary>
        /// 订单类型： 1=正常订单；2=返工返修订单
        /// </summary>
        public string WipOrderType { get; set; }

        /// <summary>
        /// 工厂
        /// </summary>
        public string Facility { set; get; }

        /// <summary>
        /// 产线
        /// </summary>
        public string ProductionLine { set; get; }

        /// <summary>
        /// 工作中心
        /// </summary>
        public string WorkCenter { set; get; }

        /// <summary>
        /// 组(用来确定唯一工艺路线)
        /// </summary>
        public string WipOrderGroup { set; get; }

        /// <summary>
        /// 组计数器 (用来确定唯一工艺路线)
        /// </summary>
        public string GroupCount { set; get; }

        /// <summary>
        /// 实际完成数量
        /// </summary>
        public int ActQuantity { set; get; }
        /// <summary>
        /// 订单物料
        /// </summary>
        public string ProductNo { set; get; }

        /// <summary>
        /// 订单物料描述
        /// </summary>
        public string ProductName { set; get; }

        /// <summary>
        /// 订单物料简码
        /// </summary>
        public string ProductAlias { set; get; }

        /// <summary>
        /// 序列号
        /// </summary>
        public string SerialNo { set; get; }

        /// <summary>
        /// 数量
        /// 12,3
        /// </summary>
        public decimal Quantity { set; get; }

        /// <summary>
        /// 计划开始时间yyyy-mm-ddhh24:mi:ss
        /// </summary>
        public string ScheduledStartDate { set; get; }

        /// <summary>
        /// 计划结束时间yyyy-mm-ddhh24:mi:ss
        /// </summary>
        public string ScheduledCompleteDate { set; get; }
        /// <summary>
        /// 订单状态
        /// </summary>
        public string ProgressStatus { set; get; }
        /// <summary>
        /// 预留参数1
        /// </summary>
        public string paramRsrv1 { set; get; } 
        /// <summary>
        /// 预留参数2
        /// </summary>
        public string paramRsrv2 { set; get; }
           /// <summary>
        /// 预留参数3
        /// </summary>
        public string paramRsrv3 { set; get; }
           /// <summary>
        /// 预留参数4
        /// </summary>
        public string paramRsrv4 { set; get; }
           /// <summary>
        /// 预留参数5
        /// </summary>
        public string paramRsrv5 { set; get; }

        /// <summary>
        /// 下发时间
        /// </summary>
        public DateTime? IssuedTime { set; get; }
    }

    public partial class Plan : BusEntity
    {
        /// <summary>
        /// 订单工序
        /// </summary>
        public virtual List<OprSequence> OprSequences { set; get; }
    }

    /// <summary>
    /// 实体配置
    /// OnModelCreating
    /// </summary>
    public class PlanTypeConfig : BusEntityTypeConfig<Plan>, IEntityTypeConfiguration<Plan>
    {
        public override void Configure(EntityTypeBuilder<Plan> builder)
        {
            base.Configure(builder);

            #region 主外键关系
            #endregion

            #region 字段属性:最大长度,是否必需,默认值
            builder.Property(p => p.MonTaskId).HasMaxLength(64);
            builder.Property(p => p.WipOrderNo).HasMaxLength(24).IsRequired();
            builder.Property(p => p.WipOrderType).HasMaxLength(8).IsRequired();
            builder.Property(p => p.Facility).HasMaxLength(8).IsRequired();
            builder.Property(p => p.ProductionLine).HasMaxLength(40).IsRequired();
            builder.Property(p => p.Status).IsRequired();
            builder.Property(p => p.WorkCenter).HasMaxLength(40);
            builder.Property(p => p.WipOrderGroup).HasMaxLength(8);
            builder.Property(p => p.GroupCount).HasMaxLength(8);
            builder.Property(p => p.ProductNo).HasMaxLength(32);
            builder.Property(p => p.ProductName).HasMaxLength(400);
            builder.Property(p => p.ProductAlias).HasMaxLength(40);
            builder.Property(p => p.Quantity).HasMaxLength(12).IsRequired();
            builder.Property(p => p.ScheduledStartDate).HasMaxLength(30).IsRequired();
            builder.Property(p => p.ScheduledCompleteDate).HasMaxLength(30).IsRequired();
            builder.Property(p => p.ProgressStatus).HasMaxLength(200).IsRequired();
            builder.Property(p => p.SerialNo).HasMaxLength(2000);
            builder.Property(p => p.paramRsrv1).HasMaxLength(64);
            builder.Property(p => p.paramRsrv2).HasMaxLength(64);
            builder.Property(p => p.paramRsrv3).HasMaxLength(64);
            builder.Property(p => p.paramRsrv4).HasMaxLength(64);
            builder.Property(p => p.paramRsrv5).HasMaxLength(64);
            builder.Property(p => p.IssuedTime);
            #endregion

            #region 备注
            builder.HasComment("计划(生产订单)");
            builder.Property(p => p.MonTaskId).HasComment("Mon任务编号");
            builder.Property(p => p.WipOrderNo).HasComment("订单号");
            builder.Property(p => p.WipOrderType).HasComment("订单类型");
            builder.Property(p => p.Facility).HasComment("工厂");
            builder.Property(p => p.ProductionLine).HasComment("产线");
            builder.Property(p => p.Status).HasComment("计划状态");
            builder.Property(p => p.WorkCenter).HasComment("工作中心");
            builder.Property(p => p.WipOrderGroup).HasComment("组");
            builder.Property(p => p.GroupCount).HasComment("组计数器");
            builder.Property(p => p.ProductNo).HasComment("订单物料");
            builder.Property(p => p.ProductName).HasComment("订单物料描述");
            builder.Property(p => p.ProductAlias).HasComment("订单物料简码");
            builder.Property(p => p.Quantity).HasComment("数量");
            builder.Property(p => p.ScheduledStartDate).HasComment("计划开始时间");
            builder.Property(p => p.ScheduledCompleteDate).HasComment("计划结束时间");
            builder.Property(p => p.ProgressStatus).HasComment("订单状态");
            builder.Property(p => p.paramRsrv1).HasComment("预留参数1");
            builder.Property(p => p.paramRsrv2).HasComment("预留参数2");
            builder.Property(p => p.paramRsrv3).HasComment("预留参数3");
            builder.Property(p => p.paramRsrv4).HasComment("预留参数4");
            builder.Property(p => p.paramRsrv5).HasComment("预留参数5");
            builder.Property(p => p.IssuedTime).HasComment("下发时间");
            #endregion

            #region 种子数据
            #endregion
        }
    }
}
